Skip to content

Conversation

@mesies
Copy link

@mesies mesies commented Nov 20, 2024

This PR was created to solve #235, on the premise that upgrade from 4.2.2 to 5.0.1 should have no breaking changes,

The reason for the issue is that for example Decorator3 does not request IDecoratedService but requests a concrete class that implements IDecoratedService.
This behavior is supported by ActivatorUtilities.CreateInstance since it uses the IServiceProvider to inject constructor arguments,
but ActivatorUtilities.CreateFactory expects the contructor to have IDecoratedService, which is not the case in this example.

public class Decorated : IDecoratedService
{
        public Decorated(IService injectedService = null)
        {
            InjectedService = injectedService;
        }

        public IService InjectedService { get; }
}

public class Decorator3 : IDecoratedService
{
        public Decorator3(Decorated inner)
        {
            Inner = inner ?? throw new ArgumentNullException(nameof(inner));
        }

        public Decorated Inner { get; }
}

Thanks for all the hard work!
Let me know what you think

@khellang khellang merged commit 698a4bb into khellang:master Dec 23, 2024
@khellang
Copy link
Owner

Thank you @mesies! 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants